﻿//#include rfm

(function() {

if (!rfm.ui) {
    rfm.ui = {};
}

/**
 * Basic navigation state element
 * @param {Element} pageElement The DOM element representing the page
 * @param {Object} pageData (Optional) Data to feed to the page
 */
rfm.ui.Page = function(pageElement, pageData) {
    this.root = pageElement;
    this.data = pageData;
};
rfm.ui.Page.prototype = {
    /**
     * Loads all content for the page, then executes a callback
     * @param {Function} oncomplete (Optional) The function to execute when loading is complete
     */
    preload: function(oncomplete) {
        if (oncomplete) {
            oncomplete.call(this);
        }
    },
    /**
     * Transitions to this page's state
     * @param {Element} container The container for the page
     * @param {Function} oncomplete (Function) If specified, a function to be called when the transition is completed
     */
    transitionIn: function(container, oncomplete) {
        container.appendChild(this.root);
        if (oncomplete) {
            oncomplete.call(this);
        }
    },
    /**
     * Transitions away from this page's state and finalizes the page
     * @param {Function} oncomplete (Function) If specified, a function to be called when the transition is completed
     */
    transitionOut: function(oncomplete) {
        if (oncomplete) {
            oncomplete.call(this);
        }
        this.finalize();
    },
    /**
     * Handles an orientation change event
     * @param {Event} e The orientation change event
     * @param {Boolean} isPortrait Whether or not the new orientation is portrait (taller than wider)
     */
    onorientationchange: function(e, isPortrait) {
        // Do nothing
    },
    /**
     * Immediately destroys the page and cleans up
     */
    finalize: function() {
        if (this.root) {
            if (this.root.parentNode) {
                this.root.parentNode.removeChild(this.root);
            }
            this.root = null;
        }
    }
};

})();